<template>
  <div>
    <el-table :data="list" style="width: 100%">
      <el-table-column prop="no" label="订单号"> </el-table-column>
      <el-table-column prop="receiver" label="姓名"> </el-table-column>
      <el-table-column prop="regionss" label="地址"></el-table-column>
      <el-table-column prop="price" label="价钱"></el-table-column>
      <el-table-column prop="isPayed" label="是否付款">
        <template slot-scope="scope">
          <!-- <el-radio v-model="item.radio" label="1">未支付</el-radio>
          <el-radio v-model="item.radio" label="2">已支付</el-radio> -->
          <span>{{scope.row.isPayed | isPay}}</span>
        </template>

      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button type="primary" @click="ddedit(scope.row._id)">支付</el-button>
          <el-button type="danger" @click="ddsc(scope.row._id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @current-change="pageChange"
      layout="prev, pager, next"
      :page-count="pages"
    >
    </el-pagination>
  </div>
</template>
<script>
import {order,orderPut,orderEdit,orderDelete} from '../../api/order'
export default {
  data(){
    return{
      list:[],
      pages:1,
      falg:false,
      id:"",
      regions:""
    }
  },
  async created(){
    this.Res()
  },
  methods:{
    async pageChange(page) {
      //console.log(page);
      this.Res(page);
    },
    async Res(page=1){
      const res = await order({page})

    //   for(let i=0;i<res.data.orders.length;i++){
    //   if(res.data.orders[i].isPayed == true){
    //     res.data.orders[i].radio = "2"
    //   }else{
    //     res.data.orders[i].radio = "1"
    //   }

    // }
    this.list = res.data.orders
    this.pages = res.data.pages;
    for(let i=0;i<res.data.orders.length;i++){
      if(res.data.orders[i].regions){
        this.list[i].regionss = res.data.orders[i].regions + res.data.orders[i].address
      }
    }

      console.log(this.list)
    },
    async DDPut(id,falg){
      const ress = await orderPut(id,{"isPayed":falg})
      console.log(ress)
    },
    async ddedit(id){
      this.falg = Boolean(1)
      console.log(id,this.falg)
      this.DDPut(id,this.falg)
      this.$router.go(0)
    },
    async ddsc(id){
      this.$confirm("此操作将永久删除该信息, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        center: true
      }).then(() => {
          orderDelete(id).then(resy => {
            console.log(resy);
            this.$router.go(0);
          });
          this.$message({
            type: "success",
            message: "删除成功!"
          });
        })
        .catch(err => {
          this.$message({
            type: "info",
            message: "已取消删除"
          });
        });

    }
  },
  filters:{
    isPay(isPayed){
      if(isPayed == false){
        return "未支付"
      }else{
        return "已支付"
      }
    }
    }
  }
</script>
